<?if(!defined("PROLOG_INCLUDED") || PROLOG_INCLUDED!==true)die();

/**
 * События
 */
class Event {
	private static $arEvents = Array();

	//Event::Add("catalog", "OnBeforeCatalogElementAdd", Array("Class", "OnBeforeCatalogElementAddHandler"));
	public static function Add($moduleName, $eventName, $eventHandler) {
		self::$arEvents[$moduleName][$eventName][] = $eventHandler;
	}

	public static function GetList($moduleName) {
		$arEvt = self::$arEvents[$moduleName];
		if (empty($arEvt)) {
			$arEvt = Array();
		}
		return $arEvt;
	}

	public static function Run($moduleName, $eventName, &$arParams) {
		$arEvts = self::$arEvents[$moduleName][$eventName];
		if (!empty($arEvts)) {
			foreach ($arEvts as $event) {
				if (is_array($event) && !empty($event) && count($event) == 2) {
					$class = new $event[0]();
					$method = $event[1];
					$class->$method($arParams);
				}
				elseif (is_string($event)) {
					$event($arParams);
				}
			}
		}
	}
}
?>